package com.lintf.distributed.transaction.inventory.exception;

import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.kafka.listener.KafkaListenerErrorHandler;
import org.springframework.kafka.listener.ListenerExecutionFailedException;
import org.springframework.messaging.Message;
import org.springframework.stereotype.Component;

@Component
public class CustomKafkaErrorHandler implements KafkaListenerErrorHandler {

    private static final Logger log = LoggerFactory.getLogger(CustomKafkaErrorHandler.class);

    @Override
    public Object handleError(Message<?> message, ListenerExecutionFailedException exception) {
        log.error("Kafka 消息处理失败: payload={}, headers={}",
                message.getPayload(), message.getHeaders(), exception);
        // 可以发送到死信队列、记录数据库、触发补偿机制等
        return null;
    }
}
